package com.ruoyi.project.system.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.framework.web.domain.BaseEntity;
import com.ruoyi.project.system.domain.vo.UserProduct;
import lombok.Data;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@Accessors(chain = true)
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    private Long userId;

    private String userName;

    private String password;

    private String nickName;

    private Long roleId;

    private String email;

    private String phonenumber;

    private BigDecimal balance;

    private String identityCode;

    private String command;

    private String loginIp;

    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date loginDate;

    private Long parent;

    private String grade;

    private String commissionType;

    private Float commissionRate;

    private String dataHide;

    private String status;

    private String delFlag;

    private List<SysRole> roles;

    public SysUser() {
    }

    public SysUser(String userName) {
        this.userName = userName;
    }

    public SysUser(UserProduct up) {
        this.userId = up.getUserId();
        this.userName = up.getUserName();
    }

    public boolean isAdmin() {
        return isAdmin(this.roleId);
    }

    public static boolean isAdmin(Long roleId) {
        return roleId != null && 1L == roleId;
    }

}
